package com.atmaowei.service.impl;

import com.atmaowei.entity.Department;
import com.atmaowei.entity.Student;
import com.atmaowei.mapper.ChartMapper;
import com.atmaowei.service.ChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ChartServiceImpl implements ChartService {

    @Autowired
    private ChartMapper chartMapper;

    @Override
    public String getNumOfMale() {
        return chartMapper.getNumOfMale();
    }

    @Override
    public String getNumOfFemale() {
        return chartMapper.getNumOfFemale();
    }

    @Override
    public Integer[] getNumOfAge() {
        Integer a1 = 0, a2 = 0, a3 = 0, a4 = 0;
        List<Student> students = chartMapper.getAllStudent();
        for (Student student : students) {
            if (student.getSage().equals("21")) {
                a1++;
            } else if (student.getSage().equals("22")) {
                a2++;
            } else if (student.getSage().equals("23")) {
                a3++;
            } else if (student.getSage().equals("24")) {
                a4++;
            }
        }
        Integer array[] = {a1, a2, a3, a4};
        return array;
    }

    @Override
    public List<String> getAllDepartment() {
        return chartMapper.getAllDepartment();
    }

    @Override
    public List<String> getNumOfDepartment() {
        List<String> departments = getAllDepartment();
        List<String> nums = new ArrayList<>();
        for (String department : departments) {
            nums.add(chartMapper.getNumOfDepartment(department));
        }
        return nums;
    }

    @Override
    public String getTotal(String name) {
        if (name.equals("student")) {
            return chartMapper.getTotalOfStudent();
        } else if (name.equals("teacher")) {
            return chartMapper.getTotalOfTeacher();
        } else if (name.equals("course")) {
            return chartMapper.getTotalOfCourse();
        } else if (name.equals("department")) {
            return chartMapper.getTotalOfDepartment();
        } else if (name.equals("sct")) {
            return chartMapper.getTotalOfSct();
        }
        return null;
    }
}
